<template>
	<view>
		<!-- <web-view :webview-styles="webviewStyles" src="http://121.36.106.84:8070/"></web-view> -->
		<view style="height: 30upx;"></view>
		<view style="width: 690upx;margin-left: 30upx;"><u-swiper :list="list"></u-swiper></view>
		<view style="height: 30upx;"></view>
		<view style="width: 690upx;margin-left: 30upx;"><u-notice-bar :volume-icon="true" :list="notice_list"></u-notice-bar></view>
		<view style="height: 30upx;"></view>
		<view style="width: 690upx;margin-left: 30upx;">
			<u-grid :col="3">
				<u-grid-item @click="scan_yuanliao_qrcode">
					<u-icon name="scan"  class="icon-color-blue" :size="50"></u-icon>
					<view class="grid-text">扫码原料码</view>
				</u-grid-item>
				<!-- <u-grid-item @click="goPage('/pages/oa/sign/sign')">
					<u-icon name="edit-pen" class="icon-color-blue" :size="50"></u-icon>
					<view class="grid-text">签到</view>
				</u-grid-item> -->
				<u-grid-item @click="goPage('/pages/oa/pay/pay-log','1')" v-if="this.userInfo.typecode=='1'">
					<u-icon name="order" class="icon-color-blue" :size="50"  ></u-icon>
					<view class="grid-text">支付记录</view>
				</u-grid-item>
				<u-grid-item @click="goPage('/pages/oa/car-list/add','1')" v-if="this.userInfo.typecode=='1'" >
					<u-icon name="edit-pen" class="icon-color-blue" :size="50"  ></u-icon>
					<view class="grid-text">车辆登记</view>
				</u-grid-item>
				<u-grid-item @click="goPage('/pages/oa/car-list/car-list','1')" v-if="this.userInfo.typecode=='1'" >
					<u-icon name="car" class="icon-color-blue" :size="50"></u-icon>
					<view class="grid-text">车辆管理</view>
				</u-grid-item>
				<u-grid-item @click="goPage('/pages/oa/pay/pay-car','1')">
					<u-icon name="weixin-fill" class="icon-color-blue" :size="50"></u-icon>
					<view class="grid-text">车辆支付</view>
				</u-grid-item>
				<u-grid-item @click="goPage('/pages/oa/order-log/order-log','1')" v-if="this.userInfo.typecode=='1'" >
					<u-icon name="calendar" class="icon-color-blue" :size="50"></u-icon>
					<view class="grid-text">称重记录</view>
				</u-grid-item>
				<u-grid-item @click="goPage('/pages/oa/oa-user/check-car-weight','0')" v-if="this.userInfo.typecode=='0'" >
					<u-icon name="attach" class="icon-color-blue" :size="50"></u-icon>
					<view class="grid-text">核验水杂</view>
				</u-grid-item>
				<u-grid-item @click="goPage('/pages/oa/oa-user/check-car-weight-list','0')" v-if="this.userInfo.typecode=='0'" >
					<u-icon name="order" class="icon-color-blue" :size="50"></u-icon>
					<view class="grid-text">核验记录</view>
				</u-grid-item>
			</u-grid>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
import qs from "qs"
export default {
	computed: {
		...mapState('account', ['token', 'userInfo'])
	},
	data() {
		return {
			notice_list: ['称重系统上线了'],
			list: [
				{
					image: '/static/zsoa/banner1.png',
					title: ''
				},
				{
					image: '/static/zsoa/banner2.jpg',
					title: ''
				}
			],
			webviewStyles: {
				progress: {
					color: '#0074E0'
				}
			}
		};
	},
	methods: {
		// 识别原料二维码
		scan_yuanliao_qrcode(){
			
			// let testData = `{"驾驶员姓名":"","联系电话":"","卡号":"","车号":"","类型编码":"1","类型名称":"原料车辆","皮重":"","货物名称":"","货物编号":"","供货单位":"7月9号磅房测试采购账号","供货单位编号":"","收货单位":"新乡市长城矿粉有限公司","收货单位编号":"","备注":"","产品规格":"","产品规格编号":"","场区名称":"","场区编号":"","产地":"","产地编号":"","token":"oScpo5mUjMghNZDOxj9HjS6mEO2w","account":"bfcs"}`
			// testData = JSON.parse(testData)
			// uni.setStorageSync("agent_token",testData.token);
			// uni.setStorageSync("driver_pre_order_data",testData)
			// uni.navigateTo({
			// 	url:"/pages/oa/car-list/add?type=3"
			// })
			// return
			wxjs.scanQRCode({
				needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
				scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
				success: function (res) {
					var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
					try{
						result = JSON.parse(result);
						
					}catch(e){
						uni.showToast({
							title:"无效的二维码"
						})
						//TODO handle the exception
					}
					uni.setStorageSync("agent_token",result.token);
					uni.setStorageSync("driver_pre_order_data",result)
					uni.navigateTo({
						url:"/pages/oa/car-list/add?type=3"
					})
				}
			});


		},
		goPage(path,code) {
			if(path === "/pages/oa/pay/pay-car"){
				uni.navigateTo({
					url: path
				});
				
				return
			}
			if (this.token) {
				
				
				if(this.userInfo.Account){
					
					uni.navigateTo({
						url: path
					});
					
					// if(this.userInfo.typecode==code){
					// 	uni.navigateTo({
					// 		url: path
					// 	});
					// }else{
					// 	uni.showToast({
					// 		title:"无权访问",
					// 		icon:"none"
					// 	})
					// }
					
				}else{
					uni.showModal({
						title: '系统提示',
						content: '请先绑定账号',
						success() {},
						showCancel: false
					});
				}
				
				// uni.navigateTo({
				// 	url: "/pages/oa/car-list/add"
				// });
			} else {
				uni.showModal({
					title: '系统提示',
					content: '请重新进入，并授权',
					success() {},
					showCancel: false
				});
			}
		}
	}
};
</script>

<style lang="scss">
.icon-color-blue {
	color: $u-type-primary;
	margin-bottom: 14upx;
}
</style>
